package com.sutuijingling.result;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;

public class b {
    Map a;
    private StringBuilder b;
    private StringBuilder c;
    private boolean d;

    public b(String str, String str2, boolean z) {
        this(z);
        this.b = new StringBuilder(str + str2);
    }

    public b(boolean z) {
        this.a = new HashMap();
        this.d = z;
        if (!z) {
            this.c = new StringBuilder();
        }
    }

    public static String a(String str) {
        try {
            return URLEncoder.encode(str, "utf-8");
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

    public Map a() {
        return this.a;
    }

    public HttpUriRequest a(File file) {
        System.out.println(this.b.toString() + " with method get:" + this.d + " with body :" + this.c);
        if (file != null) {
            return new HttpPost(this.b.toString());
        }
        if (this.d) {
            String stringBuilder = this.b.toString();
            System.out.println(stringBuilder);
            return new HttpGet(stringBuilder);
        }
        HttpUriRequest httpPost = new HttpPost(this.b.toString());
        httpPost.setHeader("content-type", "application/x-www-form-urlencoded");
        try {
            httpPost.setEntity(new StringEntity(this.c.toString(), "utf-8"));
            return httpPost;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return httpPost;
        }
    }

    public void a(String str, int i) {
        a(str, String.valueOf(i));
    }

    public void a(String str, Long l) {
        a(str, String.valueOf(l));
    }

    public void a(String str, String str2) {
        StringBuilder stringBuilder = this.d ? this.b : this.c;
        if (stringBuilder.length() > 0) {
            if (this.d) {
                stringBuilder.append(this.b.indexOf("?") > 0 ? "&" : "?");
            } else {
                stringBuilder.append("&");
            }
        }
        String a = a(str);
        String a2 = a(str2);
        this.a.put(a, a2);
        stringBuilder.append(a);
        stringBuilder.append("=");
        stringBuilder.append(a2);
    }

    public void a(String str, boolean z) {
        a(str, String.valueOf(z));
    }

    public void a(boolean z) {
        this.d = z;
    }
}
